#coding=utf-8

import datetime
from openpyxl import Workbook
from openpyxl import load_workbook

class ExcelTool:
	def __init__(self):
		self.pageLink = ""
		self.isoName = ""
		self.filename = ""
		self.isoSize = ""
		self.updateTime = ""

	def SetPageLink(self,pageLink):
		self.pageLink = pageLink

	def SetISOName(self,isoName):
		self.isoName = isoName

	def SetFilename(self,filename):
		self.filename = filename

	def SetISOSize(self,isoSize):
		self.isoSize = isoSize

	def SetUpdateTime(self,updateTime):
		self.updateTime = updateTime

	#记录下载ISO镜像信息到Excel
	def LogISOInfo(self):
		filename = "下载镜像日志.xlsx"
		wb = None
		ws = None
		if not os.path.exists(filename):
			wb = Workbook()
			ws = wb.active
			ws.title = "镜像信息"
		else:
			wb = load_workbook(filename)
			if not wb:
				return
			ws = wb.get_sheet_by_name("镜像信息")
			if not ws:
				return
 		#初始化表头
		ws['A1'] = "来源网址"
		ws['B1'] = "镜像标题"
		ws['C1'] = "镜像名称"
		ws['D1'] = "镜像大小"
		ws['E1'] = "镜像更新时间"
		ws['F1'] = "镜像下载时间"

		startRow = str(len(tuple(ws.rows)) + 1)
		ws['A'+startRow] = self.pageLink
		ws['B'+startRow] = self.isoName
		ws['C'+startRow] = self.filename
		ws['D'+startRow] = self.isoSize
		ws['E'+startRow] = self.updateTime
		ws['F'+startRow] = str(datetime.datetime.now())
		wb.save(filename)

